package com.guodexian.xiaomi.service.impl;


import com.guodexian.xiaomi.dao.UserDao;
import com.guodexian.xiaomi.dao.Sql2oUserDaoImpl;
import com.guodexian.xiaomi.entity.User;
import com.guodexian.xiaomi.service.UserService;
import com.guodexian.xiaomi.tx.TransactionManager;

/**
 * 类说明：  <br>
 *
 * @author 南阳德刚<br>
 * 2024-12-30 14:48<br>
 * @since 1.0 <br>
 * 培养IT高薪技术人才的摇篮---北京学佳澳。<br>
 * 点击<a href="http://www.xuejiaao.com/images/qrcode.jpg">学佳澳教育</a>关注公共号,有惊喜(⊙o⊙)<br>
 */
public class UserServiceImpl implements UserService {
    private UserDao userDao = new Sql2oUserDaoImpl();
/*
    @Override
    public ResultVO findUserByNameAndPassword(String username, String password) {
        try {
            TransactionManager.beginTransaction();
            User user = userDao.findUserByName(username);

            if (user == null) {
                return ResultVO.fail("用户不存在");
            }
            if(! user.getPassword().equals(password)) {
                return ResultVO.fail("密码不对");
            }

            TransactionManager.commitTransaction();
            return ResultVO.success(user);
        } catch (Exception e) {
            e.printStackTrace();
            TransactionManager.rollbackTransaction();
            return ResultVO.fail(e.getMessage());
        }
    }

    */
    @Override
    public User findUserByNameAndPassword(String username, String password) {
        try {
            TransactionManager.beginTransaction();
            User user = userDao.findUserByName(username);
            TransactionManager.commitTransaction();
            return user;

        } catch (Exception e) {
            TransactionManager.rollbackTransaction();
        }
        return null;
    }


}